home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 May / macformat-024.iso / Shareware City / Developers / Kant Pro source Folder / Kant Pro 1.1 ƒ / kode new / kant main window.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-21  |  5.3 KB  |  223 lines  |  [TEXT/MMCC]

  1. #include "kant main window.h"
  2. #include "kant load-save.h"
  3. #include "drag utilities.h"
  4. #include "environment.h"
  5. #include "util.h"
  6. #include "menus.h"
  7. #include "main.h"
  8. #include "dialogs.h"
  9. #include "text twiddling.h"
  10. #include "generic window handlers.h"
  11. #include "window layer.h"
  12. #include "program globals.h"
  13.  
  14. #define kGrowBoxSize        15
  15.  
  16. static    void PutDataIntoTEFields(WindowPtr theWindow);
  17.  
  18. static    short            gOldForegroundTime;        /* stored foreground wait time */
  19. #if powerc
  20. static    TEClickLoopUPP    gClickLoopUPP;
  21. #endif
  22. static    Boolean            gSetupDone=FALSE;
  23. static    Boolean            gIsActive=FALSE;
  24.  
  25. void SetupTheMainWindow(WindowPtr theWindow)
  26. {
  27.     unsigned char    *titleStr="\puntitled";
  28.     Point            topLeft;
  29.     FSSpec            fs;
  30.     
  31.     SetWindowHeight(theWindow, qd.screenBits.bounds.bottom-qd.screenBits.bounds.top-LMGetMBarHeight()-28);
  32.     SetWindowWidth(theWindow, qd.screenBits.bounds.right-qd.screenBits.bounds.left-70);
  33.     SetWindowType(theWindow, zoomDocProc);
  34.     topLeft.v=qd.screenBits.bounds.top+LMGetMBarHeight()+20;
  35.     topLeft.h=qd.screenBits.bounds.left+10;
  36.     SetWindowTopLeft(theWindow, topLeft);
  37.     SetWindowHasCloseBox(theWindow, TRUE);
  38.     SetWindowMaxDepth(theWindow, 1);
  39.     SetWindowDepth(theWindow, 1);
  40.     SetWindowIsFloat(theWindow, FALSE);
  41.     SetWindowTitle(theWindow, titleStr);
  42.     SetWindowAutoCenter(theWindow, FALSE);
  43.     fs.name[0]=0x00;
  44.     fs.vRefNum=0;
  45.     fs.parID=0;
  46.     SetWindowFS(theWindow, fs);
  47.     SetWindowIsModified(theWindow, FALSE);
  48.     SetWindowIsDraggable(theWindow, TRUE);
  49.     
  50.     if (gSetupDone)
  51.         return;
  52.     
  53.     gSetupDone=TRUE;
  54. #if powerc
  55.     gClickLoopUPP=NewTEClickLoopProc(ClickLoopProc);
  56. #endif
  57. }
  58.  
  59. void ShutDownTheMainWindow(void)
  60. {
  61. #if powerc
  62.     if (gClickLoopUPP!=0L)
  63.         DisposeRoutineDescriptor(gClickLoopUPP);
  64. #endif
  65. }
  66.  
  67. void OpenTheMainWindow(WindowPtr theWindow)
  68. {
  69.     TEHandle        hTE;
  70.     FontInfo        theFontInfo;
  71.     Rect            vScrollBarRect, hScrollBarRect;
  72.     Rect            destRect, viewRect;
  73.     
  74.     hTE=GetWindowTE(theWindow);
  75.     if (hTE==0L)
  76.     {
  77.         SetRect(&vScrollBarRect, GetWindowWidth(theWindow)-kGrowBoxSize, -1,
  78.             GetWindowWidth(theWindow)+1, GetWindowHeight(theWindow)+1-kGrowBoxSize);
  79.         SetRect(&hScrollBarRect, -1, GetWindowHeight(theWindow)-kGrowBoxSize,
  80.             GetWindowWidth(theWindow)-kGrowBoxSize+1, GetWindowHeight(theWindow)+1);
  81.         SetWindowVScrollBar(theWindow,
  82.             NewControl(theWindow, &vScrollBarRect, "\p", TRUE, 0, 0, 0, scrollBarProc, 0));
  83.         SetWindowHScrollBar(theWindow,
  84.             NewControl(theWindow, &hScrollBarRect, "\p", TRUE, 0, 0, 0, scrollBarProc, 0));
  85.         
  86.         GetTERect(theWindow, &destRect, TRUE);
  87.         viewRect=destRect;
  88.         hTE=TENew(&destRect, &viewRect);
  89.         SetWindowTE(theWindow, hTE);
  90.         TextFont((**hTE).txFont=monaco);
  91.         TextSize((**hTE).txSize=9);
  92.         TextFace((**hTE).txFace=0);
  93.         GetFontInfo(&theFontInfo);
  94.         (**hTE).fontAscent=theFontInfo.ascent;
  95.         (**hTE).lineHeight=theFontInfo.ascent+theFontInfo.descent+theFontInfo.leading;
  96.         AdjustViewRect(hTE);
  97.         TEAutoView(TRUE, hTE);
  98.         SetWindowOldClickLoopProc(theWindow, (**hTE).clickLoop);
  99. #if powerc
  100.         TESetClickLoop(gClickLoopUPP, hTE);
  101. #else
  102.         (**hTE).clickLoop=(TEClickLoopUPP)MyClikLoop;
  103. #endif
  104.         PutDataIntoTEFields(theWindow);
  105.     }
  106.     
  107.     gIsActive=TRUE;
  108.     AdjustVScrollBar(GetWindowVScrollBar(theWindow), hTE);
  109.     AdjustMenus();
  110. }
  111.  
  112. void KeyPressedInMainWindow(WindowPtr theWindow, unsigned char theChar)
  113. {
  114.     TEHandle        hTE;
  115.     ControlHandle    vScrollBar;
  116.     
  117.     hTE=GetWindowTE(theWindow);
  118.     vScrollBar=GetWindowVScrollBar(theWindow);
  119.     
  120.     switch (theChar)
  121.     {
  122.         case 0x09:
  123.             TESetSelect(0, 32767, hTE);
  124.             break;
  125.         default:
  126.             TEKey(theChar, hTE);
  127.             SetWindowIsModified(theWindow, TRUE);
  128.             break;
  129.     }
  130.     
  131.     AdjustVScrollBar(vScrollBar, hTE);
  132. }
  133.  
  134. void DisposeTheMainWindow(WindowPtr theWindow)
  135. {
  136.     TEHandle        hTE;
  137.     
  138.     hTE=GetWindowTE(theWindow);
  139.     if (hTE!=0L)
  140.     {
  141.         TEDispose(hTE);
  142.         SetWindowTE(theWindow, 0L);
  143.     }
  144. }
  145.  
  146. Boolean CloseTheMainWindow(WindowPtr theWindow)
  147. {
  148.     ModalFilterUPP    procFilter = NewModalFilterProc(ThreeButtonFilter);
  149.     short            result;
  150.     
  151.     if (WindowIsModifiedQQ(theWindow))
  152.     {
  153.         SetCursor(&qd.arrow);
  154.         PositionDialog('ALRT', saveAlert);
  155.         ParamText(GetWindowTitle(theWindow), "\p", "\p", "\p");
  156.         result=Alert(saveAlert, procFilter);
  157.         DisposeRoutineDescriptor(procFilter);
  158.         switch (result)
  159.         {
  160.             case 1:    /* save */
  161.                 LoadSaveDispatch(FALSE, TRUE);
  162.                 if (WindowIsModifiedQQ(theWindow))    /* save didn't work for some reason */
  163.                     return FALSE;
  164.                 break;
  165.             case 2:     /* cancel */
  166.                 return FALSE;
  167.                 break;
  168.             case 3:    /* don't save */
  169.                 break;
  170.         }
  171.     }
  172.     
  173.     gCustomCursor=FALSE;
  174.     
  175.     return TRUE;
  176. }
  177.  
  178. void PasteInMainWindow(WindowPtr theWindow)
  179. {
  180.     TEHandle        hTE;
  181.     ControlHandle    vScrollBar;
  182.     Handle            scrapHandle;
  183.     long            offset;
  184.     unsigned long    scrapLength;
  185.     unsigned char    *theSource="\pMBDF-A";
  186.     unsigned char    *theTarget="\pProgramming is not a crime.";
  187.     
  188.     hTE=GetWindowTE(theWindow);
  189.     vScrollBar=GetWindowVScrollBar(theWindow);
  190.     
  191.     scrapHandle=NewHandle(0L);
  192.     if (GetScrap(scrapHandle, 'TEXT', &offset)!=noTypeErr)
  193.     {
  194.         scrapLength=GetHandleSize(scrapHandle);
  195.         if (scrapLength==theSource[0])
  196.         {
  197.             HLock(scrapHandle);
  198.             if (Mymemcompare((Ptr)*scrapHandle, (Ptr)&theSource[1], theSource[0]))
  199.             {
  200.                 ZeroScrap();
  201.                 PutScrap(theTarget[0], 'TEXT', (char*)&theTarget[1]);
  202.             }
  203.         }
  204.         
  205.         TEFromScrap();
  206.         TEPaste(hTE);
  207.         TESelView(hTE);
  208.         if (vScrollBar!=0L)
  209.             AdjustVScrollBar(vScrollBar, hTE);
  210.     }
  211.     DisposeHandle(scrapHandle);
  212. }
  213.  
  214. static    void PutDataIntoTEFields(WindowPtr theWindow)
  215. {
  216.     TEHandle            hTE;
  217.     
  218.     hTE=GetWindowTE(theWindow);
  219.     TESetSelect(0, 0, hTE);
  220.     TEKey(0x00, hTE);
  221.     TEKey(0x08, hTE);
  222. }
  223.